<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,height=device-height,inital-scale=1,maximum-scale=1.0,user-scalable=no">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no"/>
    <meta name="format-detection" content="email=no"/>
    <title>宣传物料下载</title>
    <link type="text/css" rel="stylesheet" href="css/common.css">
    <link type="text/css" rel="stylesheet" href="css/publicity.css">
</head>
<body>
<div class="publicity">
    <div class="main">
        <p class="time">2017-12-26 16:31</p>
        <textarea readonly="readonly" class="text">能否快速降低房价狂飙看夸奖哈科技部抗精神病的空间发卡巴斯基就开始代表尽快啊就开始打卡卡号的卡仕达上课的话卡升级的夸奖哈开始的卡是看见卡萨丁看哈开始夸奖哈是尽快哈补上了记得发，时刻记得不放假包括就撒娇看包括不少的别急撒地方进不了科技时代</textarea>
        <p class="btn">全文</p>
        <div class="main_image clear">
            <ul>
                <li><img src="image/zhejiang_card.png"></li>
                <li><img src="image/shanghai_card.png"></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
        <div class="download">
            <p>下载次数：998</p>
            <button class="btn_2" data-clipboard-text="能否快速降低">复制文案</button>
            <button class="btn_1">保存图片</button>
            <div class="clear"></div>
        </div>
    </div>
    <div class="main">
        <p class="time">2017-12-26 16:31</p>
        <textarea readonly="readonly" class="text">能否快速降低房价狂飙看夸奖哈科技部抗精神病的空间发卡巴斯基就开始代表尽快啊就开始打卡卡号的卡仕达上课的话卡升级的夸奖哈开始的卡是看见卡萨丁看哈开始夸奖哈是尽快哈补上了记得发，时刻记得不放假包括就撒娇看包括不少的别急撒地方进不了科技时代111111</textarea>
        <p class="btn">全文</p>
        <div class="main_image clear">
            <ul>
                <li><img src="image/zhejiang_card.png"></li>
                <li><img src="image/shanghai_card.png"></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
        <div class="download">
            <p>下载次数：998</p>
            <button class="btn_2" data-clipboard-text="能否快速降低">复制文案</button>
            <button class="btn_1">保存图片</button>
            <div class="clear"></div>
        </div>
    </div>
    <div class="main">
        <p class="time">2017-12-26 16:31</p>
        <textarea readonly="readonly" class="text">能否快速降低房价狂飙看夸奖哈科技部抗精神病的空间发卡巴斯基就开始代表尽快啊就开始打卡卡号的卡仕达上课的话卡升级的夸奖哈开始的卡是看见卡萨丁看哈开始夸奖哈是尽快哈补上了记得发，时刻记得不放假包括就撒娇看包括不少的别急撒地方进不了科技时代22222</textarea>
        <p class="btn">全文</p>
        <div class="main_image clear">
            <ul>
                <li><img src="image/zhejiang_card.png"></li>
                <li><img src="image/shanghai_card.png"></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
        <div class="download">
            <p>下载次数：998</p>
            <button class="btn_2" data-clipboard-text="能否快速降低">复制文案</button>
            <button class="btn_1">保存图片</button>
            <div class="clear"></div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="js/jquery-3.2.1.js"></script>
<script>


    //设置图片盒子的高度
    $('.main_image li').height($('.main_image li').width() + "px");
    $('.main_image').height(($('.main_image li').width() * 3 + 20) + "px");


    /**
     * 设置文本域高度
     */
    function readyNumber() {
        $('textarea').each(function () {
            this.setAttribute('style', 'height:' + (this.scrollHeight) + 'px;overflow-y:hidden;');
        }).on('input', function () {
            this.style.height = 'auto';
            this.style.height = (this.scrollHeight) + 'px';
        })
    }


    //点击展开收起
    $('.btn').click(function () {
        if ($(this).prev().css('height') === "40px") {
            readyNumber()
            $(this).html("收起")
        }
        else {
            $(this).prev().css('height', '40px');
            $(this).html("全文")
        }
    })

    /**
     * 保存图片到本地
     * @param Url
     */
    $('.btn_1').click(function () {
        var imgs = $(this).parent().siblings('.main_image').find('img');
        console.log(imgs)
        for (var i = 0; i < imgs.length; i++) {
            saveAs(imgs[i].src)
        }
    });

    function saveAs(Url) {
        var blob = new Blob([''], {type: 'application/octet-stream'});
        var url = URL.createObjectURL(blob);
        var a = document.createElement('a');
        a.href = Url;
        a.download = Url.replace(/(.*\/)*([^.]+.*)/ig, "$2").split("?")[0];
        var e = document.createEvent('MouseEvents');
        e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
        a.dispatchEvent(e);
        URL.revokeObjectURL(url);
    }

    //复制文本
    $('.btn_2').click(function () {
        $(this).attr("data-clipboard-text", "" + $(this).parent().siblings('.text').val() + "");
        var clipboard = new Clipboard('.btn_2');
        clipboard.on('success', function (e) {
            window.getSelection().removeAllRanges();
        });
    });



</script>
</html>